package com.dt76.smallloanbackenduser.controller.lhuaw;

import com.dt76.smallloanbackenduser.remote.lhuaw.AdvertisingManagementtest;
import com.dt76.smallloanbackenduser.utils.Page;
import com.dt76.smallloanbackenduser.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/lhuaw")
public class AdvertisingManagementController {
    @Autowired
    private AdvertisingManagementtest advertisingManagementtest;

    @RequestMapping("/qryAllAdvert")
    public String AdvertisingManagement1(Model model){
        model.addAttribute("AdvertisingManagementList",advertisingManagementtest.qryAllAdvert());
        System.out.println("调用成功");
        System.out.println(advertisingManagementtest.qryAllAdvert());
        return "pages/lhuaw/AdvertisingManagement";
    }

    @RequestMapping("/qryConditionPageAllAdvertising")
    public String getConditionPageAllAdvertising(Model model,Integer currentPageNo,
                                             @RequestParam(value ="advertisingName",required = false)String advertisingName,
                                             @RequestParam(value = "advertisingLocation",required = false)String advertisingLocation
    ){
        if (currentPageNo <= 0) {
            currentPageNo = 1;
        }
        String paramadvertisingName= "";
        String paramadvertisingLocation="";
        if(advertisingName != null && ! advertisingName.equals("")){
            paramadvertisingName ="%"+advertisingName+"%";
        }
        if(advertisingLocation !=null && ! advertisingLocation.equals("")){
            paramadvertisingLocation ="%"+advertisingLocation+"%";
        }
        Page page = advertisingManagementtest.getConditionPageAllAdvertising(currentPageNo,paramadvertisingName,paramadvertisingLocation);
        model.addAttribute("qryadvertisingManagementList",page.getRows());
        model.addAttribute("page",page);
        model.addAttribute("advertisingName",advertisingName);
        model.addAttribute("advertisingLocation",advertisingLocation);
        System.out.println(page.getRows());
        return "pages/lhuaw/AdvertisingManagement";
    }

    //删除
    @RequestMapping("/delAdvertising/{advId}")
    @ResponseBody
    public Result delAdvertising(@PathVariable String advId){
        return advertisingManagementtest.delAdvertising(Integer.parseInt(advId));
    }

}
